package com.blockmeta.bbs.immodule.widget;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.blockmeta.bbs.baselibrary.utils.ToastUtil;
import com.blockmeta.bbs.baselibrary.widget.dialog.RxDialog;
import com.blockmeta.bbs.immodule.R;


/**
 * Created by vondear on 2016/7/19.
 * Mainly used for confirmation and cancel.
 */
public class RxDialogAddFriend extends RxDialog implements View.OnClickListener{

    private TextView mTvSure;
    private TextView mTvCancel;
    private EditText editText;
    private TextView mTvTitle;

    public RxDialogAddFriend(Context context, int themeResId) {
        super(context, themeResId);
        initView();
    }

    public RxDialogAddFriend(Context context, boolean cancelable, DialogInterface.OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initView();
    }

    public RxDialogAddFriend(Context context) {
        super(context);
        initView();
    }

    public RxDialogAddFriend(Activity context) {
        super(context);
        initView();
    }

    public RxDialogAddFriend(Context context, float alpha, int gravity) {
        super(context, alpha, gravity);
        initView();
    }


    public void setTitle(String title) {
        mTvTitle.setText(title);
    }

    public TextView getTitleView() {
        return mTvTitle;
    }

    public EditText getEditText() {
        return editText;
    }

    public TextView getSureView() {
        return mTvSure;
    }

    public void setSure(String strSure) {
        this.mTvSure.setText(strSure);
    }

    public TextView getCancelView() {
        return mTvCancel;
    }

    public void setCancel(String strCancel) {
        this.mTvCancel.setText(strCancel);
    }

    private void initView() {
        View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_add_friend, null);
        mTvTitle =  dialogView.findViewById(R.id.tv_title);
        mTvSure = dialogView.findViewById(R.id.tv_sure);
        mTvCancel = dialogView.findViewById(R.id.tv_cancle);
        editText =  dialogView.findViewById(R.id.editText);

        mTvCancel.setOnClickListener(this);
        mTvSure.setOnClickListener(this);
        setContentView(dialogView);
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.tv_cancle) {
            dismiss();

        } else if (i == R.id.tv_sure) {
            String input = editText.getText().toString().trim();
            if (TextUtils.isEmpty(input)) {
                ToastUtil.show("请输入正确的id");
            }
            dismiss();
            if (mOnSureListener != null) {
                mOnSureListener.onSureListener(input);
            }

        } else {
        }
    }

    /**
     * 点击确定按钮时获取输入内容
     */
    public interface OnSureListener{
        void onSureListener(String input);
    }

    private OnSureListener mOnSureListener;

    public void setOnSureListener(OnSureListener onSureListener) {
        mOnSureListener = onSureListener;
    }
}
